package com.yuyou.hxyy.service.api.Async;

import com.yuyou.hxyy.service.api.entity.Word;
import com.yuyou.hxyy.service.api.enums.CommEnums;
import com.yuyou.hxyy.service.api.service.IWordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * Create by chengsiyuan on 2018/6/14-11:17
 **/
@Component
public class AsyncService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IWordService wordService;

    @Async("taskExecutor")
    public void AsynUploadJob(Word w){
        if(w.getWordId() != null && wordService.selectByPrimaryKey(w.getWordId()) != null){
            if(wordService.dealWordUrl(w)){
                w.setStatus(CommEnums.urlStatus.done.getValue());
                wordService.updateByPrimaryKeySelective(w);
            }
            logger.info(Thread.currentThread().getName()+"-上传单词音频到七牛云:"+w.getWordId()+"_"+w.getEn());
        }
    }
}
